<?php
/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:用户扩展应用权限
 * @LastEditors: liuhongbin
 */

namespace app\common\model\addonAuth;


use app\common\model\BaseModel;

class UserAddon extends BaseModel
{
    protected $autoWriteTimestamp = false;
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'user_addon';

    /**
     * 字段类型或者格式转换
     * @var array
     */
    protected $type = [
        'addons' => 'json',
    ];


    public function saveAddons($uid, $addons)
    {
        $user_addon = $this->where(['uid' => $uid])->findOrEmpty();
        $user_addon->uid = $uid;
        $user_addon->addons = $addons;
        $user_addon->save();
    }

    public function getAddons($uid)
    {
        $row = $this->where(['uid' => $uid])->find();
        if (!$row) {
            return [];
        }
        return $row->addons;
    }
}